package com.zgf.easy.proxy.groovy.loader;

import groovy.lang.GroovyClassLoader;
import org.codehaus.groovy.control.CompilerConfiguration;
import org.springframework.util.StringUtils;

public class GroovyLoader {

    private static GroovyClassLoader groovyClassLoader;

    static {
        CompilerConfiguration configuration = new CompilerConfiguration();
        configuration.setSourceEncoding("UTF-8");
        groovyClassLoader = new GroovyClassLoader(GroovyLoader.class.getClassLoader(), configuration);
    }

    public static Class<?> getClass(String content) {
        if (StringUtils.isEmpty(content)) {
            return null;
        }
        return groovyClassLoader.parseClass(content);
    }

}
